OpenUltrasonic
Initializes and sets the mode of the NXT ultrasonic sensor
Contents
Syntax
OpenUltrasonic(port)
OpenUltrasonic(port, mode)
OpenUltrasonic(port, mode, handle)
Description
OpenUltrasonic(port) initializes the input mode of NXT ultrasonic sensor specified by the sensor port. The value port can be addressed by the symbolic constants SENSOR_1 , SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick.
OpenUltrasonic(port, mode) can enable the snapshot mode if the value mode is equal to the string 'snapshot'. This mode provides the snap shot mode (or SINGLE_SHOT mode) of the NXT ultrasonic sensor, which provides several sensor readings in one step. See USMakeSnapshot for more information.
The last optional argument can be a valid NXT handle. If none is specified, the default handle will be used (call COM_SetDefaultNXT to set one).
Since the NXT ultrasonic sensor is a digital sensor (that uses the I²C protocol), the function NXT_SetInputMode cannot be used as for analog sensors.
Note:
When the US sensor is opened in snapshot mode, the function GetUltrasonic does not work correctly!
Examples
OpenUltrasonic(SENSOR_4); distance = GetUltrasonic(SENSOR_4); CloseSensor(SENSOR_4);
port = SENSOR_4; OpenUltrasonic(port, 'snapshot'); % send out the ping USMakeSnapshot(port); % wait some time for the sound to travel pause(0.1); % 100ms is probably too much, calculate using c_sound ;-) % retrieve all the echos in 1 step echos = USGetSnapshotResults(port); CloseSensor(SENSOR_4);
See also
GetUltrasonic, USMakeSnapshot, USGetSnapshotResults, CloseSensor
Signature
- Author: Linus Atorf, Alexander Behrens (see AUTHORS)
- Date: 2008/01/08
- Copyright: 2007-2008, RWTH Aachen University